//
//  WBMainViewController.m
//  WeiBoOC
//
//  Created by 韩菲菲 on 16/8/9.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

#import "WBMainViewController.h"
#import "WBTabBar.h"
#import "WBComposeViewController.h"
#import "WBUserAccountViewModel.h"

@interface WBMainViewController ()<WBTabBarDelegate>

@end

@implementation WBMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    WBTabBar *tabbar = [[WBTabBar alloc] init];
    
    //设置代理
    tabbar.WBDelegate = self;
    
    //设置自定义tabbar 先自定义tabbar 再添加子控制器  不然不会默认选中第一个
    [self setValue:tabbar forKey:@"tabBar"];

    //添加子控制器
    [self addChildViewControllers];
    
    

}

//实现代理方法
- (void)btnClick
{

    //先判断用户有没有登录
    if([WBUserAccountViewModel sharedWBUserAccountViewModel].isLogin)
    {
        //登录了
        //弹出发布微博的控制器
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[WBComposeViewController alloc] init]];
        
        //modal弹出
        [self presentViewController:nav animated:YES completion:nil];
    
    }else
    {
        NSLog(@"用户没有登录");
    
    }
    
    

}


- (void)addChildViewControllers
{
    
 
    
    self.viewControllers = @[
                             [[UINavigationController alloc] initWithRootViewController:[self creatViewControllerWithImageName:@"tabbar_home" andViewControllerName:@"WBHomeViewController" andTitle:@"首页"]],
                             [[UINavigationController alloc] initWithRootViewController:[self creatViewControllerWithImageName:@"tabbar_message_center" andViewControllerName:@"WBMessageViewController" andTitle:@"消息"]],
                             [[UINavigationController alloc] initWithRootViewController:[self creatViewControllerWithImageName:@"tabbar_discover" andViewControllerName:@"WBDiscoverViewController" andTitle:@"发现"]],
                             [[UINavigationController alloc] initWithRootViewController:[self creatViewControllerWithImageName:@"tabbar_profile" andViewControllerName:@"WBProfileViewController" andTitle:@"我"]]

                             ];



}

//根据控制器的名字 图片 和 文字 创建控制器
- (UIViewController *)creatViewControllerWithImageName:(NSString *)imageName andViewControllerName:(NSString *)vcName andTitle:(NSString *)title
{
    
    //创建控制器 
    UIViewController *vc = [[NSClassFromString(vcName) alloc] init];
    
    vc.title = title;
    
    //设置文字颜色
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:AppColor} forState:UIControlStateSelected];
    //设置图片 和 渲染颜色
    vc.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    return vc;

}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
